package com.wxtt.android.item;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.fast.dev.frame.Adapter.recycleview.HolderUtils;
import com.fast.dev.frame.Adapter.recycleview.IExpandable;
import com.fast.dev.frame.Adapter.recycleview.IItem;
import com.fast.dev.frame.Adapter.recycleview.ViewHolderFactory;
import com.fast.dev.frame.Adapter.recycleview.items.AbstractItem;
import com.wxtt.android.R;

import java.util.List;

/**
 * 说明：SampleItem
 * <p/>
 * 作者：fanly
 * <p/>
 * 时间：2016/1/24 1:04
 * <p/>
 * 版本：verson 1.0
 */
public class SampleItem extends AbstractItem<SampleItem,SampleItem.ViewHolder> implements IExpandable<SampleItem,IItem> {

    public String header;
    private boolean mExpanded = false;
    private List<IItem> mSubItems;

    private String name;

    public SampleItem withName(String name){
        this.name = name;
        return this;
    }

    public SampleItem withHeader(String header){
        this.header = header;
        return this;
    }

    @Override
    public ViewHolderFactory getFactory() {
        return new ItemFactory();
    }

    @Override
    public boolean isExpanded() {
        return mExpanded;
    }

    @Override
    public SampleItem withIsExpanded(boolean expanded) {
        this.mExpanded = expanded;
        return this;
    }

    @Override
    public SampleItem withSubItems(List<IItem> subItems) {
        this.mSubItems = subItems;
        return this;
    }

    @Override
    public List<IItem> getSubItems() {
        return mSubItems;
    }

    @Override
    public int getLayoutRes() {
        return R.layout.item_wx_article_demo;
    }

    @Override
    public int getType() {
        return R.id.wx_recyler_view_list_item_id;
    }

    public static class ItemFactory implements ViewHolderFactory<ViewHolder> {
        public ViewHolder create(View v) {
            return new ViewHolder(v);
        }
    }


    protected static class ViewHolder extends RecyclerView.ViewHolder{
        public TextView tv;
        public ViewHolder(View view){
            super(view);
            tv = (TextView) view.findViewById(R.id.tv);
        }
    }

    @Override
    public void bindView(ViewHolder holder) {
        super.bindView(holder);
        HolderUtils.setText(holder.tv,name);
    }
}
